﻿using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindStyle.SPEntity;
using WindStyle.SPEntity.Attributes;
using WindStyle.SPEntity.Converters;

namespace UnitTest
{
    public class CustomPropertyEntity : Entity
    {
        [Field("SingleLine")]
        public CustomProperty Property { get; set; }
    }

    [Converter(typeof(CustomPropertyConverter))]
    public class CustomProperty
    {
        public char[] Chars { get; set; }
    }

    public class CustomPropertyConverter : IValueConverter
    {
        public object ToFieldValue(object value, Type targetType, ConversionContext context)
        {
            return new string((value as CustomProperty).Chars);
        }

        public object ToPropertyValue(object value, Type targetType, ConversionContext context)
        {
            return new CustomProperty()
            {
                Chars = value.ToString().ToCharArray()
            };
        }
    }
}
